package exam.test15;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-12-12
 * Time: 11:05
 */
public class FootballClub {
    private ArrayList<Player> clubMembers; // collection of players in the club

    //-----------question (1)------------------------------------

    /**
     * Computes the average latest score of all the club members.
     *
     * @return the average score
     */
    public double getAverageLatestScore() {
        if (clubMembers.size() == 0) {
            return 0D;
        }

        double sum = 0;
        for (Player player : clubMembers) {
            sum += player.getLatestScore();
        }
        return sum / clubMembers.size();
    }

    //------------question (2)-------------------------------------

    /**
     * Extracts a common.list of players whose latest score is winthin a given range.
     *
     * @param minScore the minimum score threshold
     * @param maxScore the maximum score threshold
     * @return the common.list of soccerplayers with a latest score in the given range
     */
    ArrayList<Player> getPlayersInRange(double minScore, double maxScore) {
        ArrayList<Player> list = new ArrayList<>();
        for (Player player : clubMembers) {
            if (player.getLatestScore() >= minScore && player.getLatestScore() <= maxScore) {
                list.add(player);
            }
        }
        return list;
    }


    //------------question (3)-------------------------------------

    /**
     * find the player(s) having the highest payment in the club.
     *
     * @return the player(s) having the highest payment
     */
    ArrayList<Player> getPlayerWithHighestPay() {
        double highestPayment = Integer.MIN_VALUE;
        for (Player player : clubMembers) {
            if (highestPayment < player.getPayment()) {
                highestPayment = player.getPayment();
            }
        }

        ArrayList<Player> list = new ArrayList<>();
        for (Player player : clubMembers) {
            if (highestPayment == player.getPayment()) {
                list.add(player);
            }
        }
        return list;
    }
}